import axios from "axios";

// 抖音登录
export const getLoginQrcode = async () => {
  return axios
    .get(
      "https://open.douyin.com/oauth/get_qrcode/?scope=mobile,user_info,video.create,video.data&client_key=aw7tduvjdk1a0x3r&next=https:%2F%2Fbuyin.jinritemai.com%2Fmpa%2Faccount%2Flogin&state=douyin&jump_type=h5&customize_params=%7B%22comment_id%22:%22%22,%22source%22:%22qr_only%22,%22not_skip_confirm%22:%22true%22,%22open_extra%22:%22%22%7D"
    )
    .then((res) => {
      return res.data;
    })
    .catch((err) => {
      return err;
    });
};

export const checkLoginStatus = async (token) => {
  return axios
    .get(
      `https://open.douyin.com/oauth/check_qrcode/?client_key=aw7tduvjdk1a0x3r&scope=mobile,user_info,video.create,video.data&next=https:%2F%2Fbuyin.jinritemai.com%2Fmpa%2Faccount%2Flogin&state=douyin&token=${token}&jump_type=h5&customize_params=%7B%22comment_id%22:%22%22,%22source%22:%22qr_only%22,%22not_skip_confirm%22:%22true%22,%22open_extra%22:%22%22%7D`
    )
    .then((res) => {
      return res.data;
    })
    .catch((err) => {
      return err;
    });
};

//   获取抖音本地生活登录信息
export const getLoginInfo = async () => {
  return axios
    .get("https://eos.douyin.com/data/life/live/user/info/v1/")
    .then((res) => {
      return res.data;
    })
    .catch((err) => {
      return err;
    });
};

// 获取选品库商品列表


//   获取抖音本地生活商品信息
export const getLifeGoods = async () => {
  return axios
    .get(
      "https://eos.douyin.com/data/life/live/shelves/anchor/?agg_card_id=0&room_id=0&req_source=pc_current&with_promotion_price_type=true"
    )
    .then((res) => {
      return res.data;
    })
    .catch((err) => {
      return err;
    });
};

/*
抖音本地生活讲解商品
params
{
  "card_id": "", //获取已添加商品列表接口返回的 card_id
  "room_id": "", //获取直播状态接口返回的 room_id
  "operation": 3 开启, 4 关闭
  "auth_type": 7
}
*/
export const explainGoods = async (params) => {
  return axios
    .post(
      "https://eos.douyin.com/data/life/live/card/switch/",
      {
        ...params,
      },
      {
        headers: {
          "Content-Type": "application/json", // 设置请求头为 JSON
        },
      }
    )
    .then((res) => {
      return res.data;
    });
};
